﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Enterprise.Framework.Frame.Architecture;
using Resto.CostControl.Core.Query.SiteModule.ViewObject;
using Enterprise.Framework.DomainModel.Repositories;
using Resto.CostControl.Core.Domain.Model;
using Enterprise.Framework.DomainModel.Specifications;
using Enterprise.Framework.DomainModel;

namespace Resto.CostControl.Core.Query.SiteModule.QueryObject
{
    public class SiteCostQO : IApplicationQueryObject
    {
        private IQueryable<SiteCostVO> GetSiteCostVOSet()
        {
            IEntityRepository<SiteCost> repository = RestoCostDomainSession.CurrentSession.CreateEntityRepository<SiteCost>();

            IQueryable<SiteCostVO> list = from o in repository.Objects
                                          select new SiteCostVO()
                                          {
                                              ID = o.ID,
                                              ActualCost = o.ActualCost,
                                              BeginDate = o.BeginDate,
                                              EndDate = o.EndDate,
                                              ExpectedCost = o.ExpectedCost,
                                              SiteId = o.SiteID,
                                              StateCode = o.State,
                                          };

            return list;
        }

        public SiteCostVO[] QuerySiteCostVOByPager(ISpecification<SiteCostVO> spec, PagerCondition pager, string orderKey, bool isAscending)
        {
            IQueryable<SiteCostVO> list = GetSiteCostVOSet();

            if (spec != null)
                list = list.Where(spec.GetExpression());

            IEnumerable<SiteCostVO> list2 = RepositoryExtention.Query(list, pager, orderKey, isAscending);
            return list2.ToArray();
        }
    }
}
